package aspects;

import CH.ifa.draw.figures.LineConnection;
import CH.ifa.draw.framework.Figure;

public aspect SubjectObserverImpl extends SubjectObserver {
	declare parents : LineConnection implements Observer;
	declare parents : Figure implements Subject;

// Update
	public void LineConnection.update() {
		updateConnection();
	}
	
	pointcut stateChanges(Subject s) : target(s) && call(void Figure.changed());

// AddObserver

	after(LineConnection lC) : target(lC) && execution(void LineConnection.connectStart(..)) {
		lC.startFigure().addObserver(lC);
	}
	
	after(LineConnection lC) : target(lC) && execution(void LineConnection.connectEnd(..)) {
		lC.endFigure().addObserver(lC);
	}
	
	before(LineConnection lC) : target(lC) && execution(void LineConnection.disconnectStart(..)) {
		lC.startFigure().removeObserver(lC);
	}
	
	before(LineConnection lC) : target(lC) && execution(void LineConnection.disconnectEnd(..)) {
		lC.endFigure().removeObserver(lC);
	}		
}
